package ocs;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.SwingUtilities;

import ocs.gui.MainWindow;

public class MainWindowView {

    private MainWindow window;

    private MainWindowController controller;

    public MainWindowView() {
        this.window = new MainWindow();
        window.synchronizeButton.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent arg0) {
                try {
                    controller.synchronize();
                }
                catch (Exception e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }

            }
        });
    }

    public void setController(MainWindowController controller) {
        this.controller = controller;
    }

    public void display() {
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                window.setVisible(true);
            }
        });
    }

    public String getGoogleLogin() {
        return window.googleLoginTextField.getText();
    }

    public String getGooglePassword() {
        return new String(window.googlePasswordTextField.getPassword());
    }

    public String getOvsLogin() {
        return window.ovsLoginTextField.getText();
    }

    public String getOvsPassword() {
        return new String(window.ovsPasswordTextField.getPassword());
    }

    public void setOvsAccount(Account ovsAccount) {
        window.ovsLoginTextField.setText(ovsAccount.getLogin());
        window.ovsPasswordTextField.setText(ovsAccount.getPassword());
        window.ovsRemeberCheckBox.setSelected(controller.isOvsAccountMemorized());
    }

    public void setGoogleAccount(Account googleAccount) {
        window.googleLoginTextField.setText(googleAccount.getLogin());
        window.googlePasswordTextField.setText(googleAccount.getPassword());
        window.googleRemeberCheckBox.setSelected(controller.isGoogleAccountMemorized());
    }
}
